<%@ page import="java.util.ArrayList" %>
<%@ page import="Shop.ShopDaoImp" %>
<%@ page import="MannageService.Manage" %>
<%@ page import="Shop.Shop" %>
<%--
  Created by IntelliJ IDEA.
  User: 31525
  Date: 10/11/2023
  Time: 12:26 PM
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>椰子购物网</title>
    <style>
        body {
            background-image: url("MAIN10.jpeg"); /* 设置背景图片的URL */
            background-repeat: no-repeat; /* 不重复平铺背景yo图片 */
            background-size: cover;}/* 调整背景图片大小以适应页面 */
        table {
            width: 100%;
            border-collapse: collapse;
        }
        th, td {
            border: 1px solid black;
            padding: 8px;
            text-align: left;
        }
        th {
            background-color: #f2f2f2;
        }

        img {
            max-width: 100px; /* 设置最大宽度 */
            max-height: 100px; /* 设置最大高度 */
            display: block;     /* 将图片转换为块级元素 */
            margin: auto;       /* 居中显示 */
        }
    </style>

</head>
<body>

<h1>商品上架</h1>
<form action="/mavenPro000_war_exploded/ShopServlet" method="post">
   <label for="product">商品名称：</label>
    <input type="text" id="product" name="product" required>

    <label for="type">商品类型：</label>
    <select name="type"  id="type"  required>
        <option value="" disabled selected hidden>请选择商品类型</option>
        <option value="智能">智能家电 数码产品</option>
        <option value="服装">服装配饰 包包鞋子</option>
        <option value="食品">食品酒水 蔬菜水果</option>
        <option value="图书">图书 文具</option>
        <option value="电脑">电脑 办公</option>
        <option value="清洁">清洁 日用</option>
        <option value="美妆">美妆 日化</option>
    </select>


    <label for="quantity">数量：</label>
    <input type="number" id="quantity" name="quantity" min="1" required>

    <label for="price">价格：</label>
    <input type="number" id="price" name="price" min="0.01" step="0.01" required>

    <label for="image">商品图片：</label>
    <input type="file" id="image" name="image" accept="image/*" required>

    <button type="submit" name="submit">上架</button>

    <table>
        <thead>
        <tr>
            <th>商品名称</th>
            <th>商品图片</th>
            <th>类型</th>
            <th>数量</th>
            <th>价格</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        <%
            request.setCharacterEncoding("utf-8");
            ShopDaoImp s1=new ShopDaoImp();
            ArrayList<Shop> shopList = new ArrayList<>();
            Manage manage = (Manage) session.getAttribute("manage");
            if (manage == null) {
                manage = new Manage();
                // 避免直接运行时,没有通过login页面进行的登录储存用户然后报500错误,所以我给他增加了异常处理
                manage.setMname("游客");
                manage.setPassword("1111");
            }

            shopList= s1.findShop(manage.getMname());
            String name1=null;

            for (Shop shop : shopList) {
        %>
        <tr>
            <td name=i><%=shop.getProduct()%></td>
          <td ><img src="<%=shop.getUrl()%>" alt="商品图片"> </td><%--  图片只能放在webapp下,然后可以把webapp当做一个仓库,如果其他目录有跟webapp名字相同的图片,然后就可以正常显示--%>
       <td ><%=shop.getType()%></td>  <%--    从数据库获取类型中进而进行删除--%>
            <td><%=shop.getQuantity()%></td>
            <td><%=shop.getPrice()%></td>
            <%  Shop shop1 = (Shop) session.getAttribute("shop1");
                // 从session中移除名为"shop1"的对象
                session.removeAttribute("shop1");
                session.setAttribute("shop1", shop);
            %>
            <td><button  name="<%=shop.getProduct()%>"  formnovalidate>删除</button></td>
<%--            <td align="center"><input type="submit" name="<%=shop.getProduct()%>"  value="删除" formnovalidate></td>--%>
        </tr>
        <%
            }
        %>
        </tbody>
    </table>
</form>

</body>
</html>



